//
//  DPSingleton.m
//  项目A
//
//  Created by lanou3g on 15/8/31.
//  Copyright (c) 2015年 王钧. All rights reserved.
//

#import "DPSingleton.h"
#import "URLs.h"
#import "DataParsing.h"
#import "DPModel.h"
@implementation DPSingleton

static DPSingleton* s_dataBaseManager = nil;

+(DPSingleton *)defaultManager
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        s_dataBaseManager = [[DPSingleton alloc]init];
    });
    return s_dataBaseManager;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.DPdata = [[NSMutableArray alloc]init];
//        self.i = 0;
    }
    return self;
}

- (void)getDPdata:(NSInteger)number
{
    NSString * url = [NSString stringWithFormat:@"http://api.liwushuo.com/v2/items?gender=1&generation=2&limit=20&offset=%ld",(long)number];
//    NSLog(@"%@",url);
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
    NSDictionary *rootDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
    NSDictionary *dataDict = rootDict[@"data"];
    NSArray *items = dataDict[@"items"];
    for (NSDictionary *subDict in items) {
        NSDictionary *subDataDict = subDict[@"data"];
        DPModel *model = [DPModel DPModelSetValuesForKeysWithDictionary:subDataDict];
        [self.DPdata addObject:model];
    } 
}

- (void)reloadData
{
    [self.DPdata removeAllObjects];
    
}

@end
